﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using UniversalGrid.Annotations;

namespace UniversalGrid
{
    public class GridListViewModel : INotifyPropertyChanged
    {
        private ObservableCollection<GridViewModel> _gridList;

        public ObservableCollection<GridViewModel> GridList
        {
            get { return _gridList; }
        }

        private bool _isBackgroundOpaque;

        public bool IsBackgroundOpaque
        {
            get { return _isBackgroundOpaque; }
            set
            {
                if (value.Equals(_isBackgroundOpaque)) return;
                _isBackgroundOpaque = value;
                OnPropertyChanged("IsBackgroundOpaque");
            }
        }

        private bool _isInClickThroughMode;

        public bool IsInClickThroughMode
        {
            get { return _isInClickThroughMode; }
            set
            {
                if (value.Equals(_isInClickThroughMode)) return;
                _isInClickThroughMode = value;
                OnPropertyChanged("IsInClickThroughMode");
            }
        }

        private bool _isShowingBlindtext;

        public bool IsShowingBlindtext
        {
            get { return _isShowingBlindtext; }
            set
            {
                if (value.Equals(_isShowingBlindtext)) return;
                _isShowingBlindtext = value;
                OnPropertyChanged("IsShowingBlindtext");
            }
        }

        public GridListViewModel()
        {
            _gridList = new ObservableCollection<GridViewModel>();
            AddGridCommand = new DelegateCommand(AddGridAction);
            RemoveGridCommand = new DelegateCommand(RemoveGridAction);
        }

        private void RemoveGridAction(object o)
        {
            GridList.Remove(SelectedGridViewModel);
        }

        private void AddGridAction (object o)
        {
            GridList.Add(new GridViewModel());
        }

        private double _actualHeight;
        private double _actualWidth;

        public double ActualHeight
        {
            get { return _actualHeight; }
            set
            {
                if (value.Equals(_actualHeight)) return;
                _actualHeight = value;
                OnPropertyChanged("ActualHeight");
            }
        }

        public double ActualWidth
        {
            get { return _actualWidth; }
            set
            {
                if (value.Equals(_actualWidth)) return;
                _actualWidth = value;
                OnPropertyChanged("ActualWidth");
            }
        }

        private GridViewModel _selectedGridViewModel;

        public GridViewModel SelectedGridViewModel
        {
            get { return _selectedGridViewModel; }
            set { _selectedGridViewModel = value; }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

        public DelegateCommand AddGridCommand { get; set; }
        public DelegateCommand RemoveGridCommand { get; set; }
    }
}
